package com.teamwork.module03.controller;

import com.teamwork.common.entity.common.requestentity.ReqCommentBody;
import com.teamwork.common.result.Result;
import com.teamwork.module03.service.CommentService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 评论
 */
@RestController
@RequestMapping("/api/mod03/comments")
@Slf4j
public class CommentController {
    @Resource
    private CommentService commentService;

    //移动端分页查询
    @GetMapping("/page")
    public Result page(Integer page,Integer size){
        return commentService.getPage(page,size);
    }
    //管理端分页查询
    @PostMapping("/manger/page")
    public Result mangerpage(@RequestBody ReqCommentBody reqCommentBody){
        return commentService.mangerPage(reqCommentBody);
    }

    @GetMapping("/select")
    public Result getCommentsByAId(Long id){
        //log.info("查询评论id:{}",id);
        return commentService.getCommentByAid(id);
    }

    @PostMapping("/tocomment")
    public Result toCommentByAId(@RequestBody Map<String,Object> map){


        Object aid =  map.get("id");

        Object comment =map.get("comment");
        Object userid = map.get("userid");

        String comt = comment.toString();
        int aidd = Integer.parseInt(aid.toString());
        int useridd = Integer.parseInt(userid.toString());


      //  log.info("aid:commet:uid,{},{},{}",aid,comment,userid);
        return commentService.toCommentByAId(useridd,aidd,comt);

    }

    //删除单个评论
    @DeleteMapping("/deleteone/{cid}")
    public Result deleteOne(@PathVariable("cid")Integer cid){
        return commentService.deleteOne(cid);
    }
    //批量删除
    @PostMapping("/deletebuch")
    public Result deleteBuch(@RequestBody Map<String, List<Integer>> map){
        List<Integer> ids = map.get("ids");

        return commentService.deleteBuch(ids);

    }


}
